package com.woniu.cq.mallorder.service;

import com.woniu.cq.mallorder.annotation.CloudLock;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author Daniel
 * @version 1.0.0
 * @ClassName LockTestService
 * @Description RedissonClient 测试
 * @createTime 2020年09月28日 23:57:00
 */

@Service
public class LockTestService {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private RedissonClient redissonClient;
    /** 
     * @description: redisson 锁 
     * @param:  
     * @return: void 
     */
    /*public void deleteCount() {
        RLock lock = null;
        try {
            lock = redissonClient.getLock("count:1");
            lock.tryLock(30,20, TimeUnit.SECONDS);
            Integer count = Integer.parseInt(stringRedisTemplate.opsForValue().get("count"));
            if (count > 0 ){
                count--;
                stringRedisTemplate.opsForValue().set("count",count+"");
            }
        } catch (Exception e) {
            e.printStackTrace();

        }finally {
            if (lock !=null){
                lock.unlock();
            }
        }
    }*/

    /** 
     * @description: aop 注解
     * @param: null 
     * @return:  
     */
    /*@CloudLock(key = "count")
    public void lockTest(){
        System.out.println("aop注解测试");
    }*/
    @CloudLock("pl")
    public void lockTest(){
        System.out.println("封装");
    }
}
